﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace Gype.GUI
{
    public abstract class Component
    {
        internal abstract void RenderObject();
        internal abstract void RenderTopLevel();

        internal virtual void attachedToParent(Components.ItemsControl parent)
        {

        }

        internal virtual void AttachedToManager(Manager mgr)
        {
            mGUIManager = mgr;
        }

        internal virtual void OnMessage(Components.ControlMessage message)
        {
        }

        internal virtual PointF getChildOffset()
        {
            return new PointF(0, 0);
        }

        internal PointF getAbsoluteLocation()
        {
            if (Parent == null)
                return Location;

            var retPoint = Parent.getAbsoluteLocation();
            retPoint.X += Parent.getChildOffset().X + Location.X;
            retPoint.Y += Parent.getChildOffset().Y + Location.Y;

            return retPoint;
        }

        protected virtual void CalculateClientRect()
        {
            ClientRectangle = WindowRectangle;
        }

        protected virtual void SizeLocationChanged()
        {
            WindowRectangle = new RectangleF(new PointF(0, 0), Size);
            CalculateClientRect();
        }

        public RectangleF ClientRectangle { get; protected set; }
        public RectangleF WindowRectangle { get; protected set; }
        public Component Parent { get; set; }
        public PointF Location { get { return mLocation; } set { mLocation = value; SizeLocationChanged(); } }
        public SizeF Size { get { return mSize; } set { mSize = value; SizeLocationChanged(); } }

        protected PointF mLocation;
        protected SizeF mSize;

        internal Manager mGUIManager;
    }
}
